package cn.foo.service.impl;

import cn.foo.dao.UserDao;
import cn.foo.pojo.User;
import cn.foo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author Frank
 * @date 07-08
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public User login(String userCode, String userPassword) {
        User find = new User();
        find.setUserCode(userCode);
        find.setUserPassword(userPassword);
        Optional<User> optional = userDao.findOne(Example.of(find));
        return optional.isPresent()?optional.get():null;
    }

    @Override
    public List<User> findUsers() {
        return userDao.findAll();
    }
}
